﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace FPTPages.NewsPage
{
    public partial class NewsPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        public string getTBLLinks()
        {
            string st = "";
            StringBuilder builder = new StringBuilder();
            DataSet ds = new DataSet();

            string sql = "select top 5 PostTitle,PostId from Posts where typePost = 'TBL' ORDER BY DATEPOST";
            string url = ConfigurationManager.ConnectionStrings["ProjectDatabaseConnectionString2"].ToString();

            using (SqlConnection con = new SqlConnection(url))
            {
                using (SqlDataAdapter da = new SqlDataAdapter(sql, con))
                {
                    da.Fill(ds);
                }
            }

            foreach (DataRow item in ds.Tables[0].Rows)
            {
                builder.Append(@"<li><a href=""ReadNews.aspx?postid= " + item[1].ToString()+
                    @" ""> " + item[0].ToString().Trim() + "</a></li>\n");
            }

            st = builder.ToString();
            return st;
        }
        public string getTGGLinks()
        {
            string st = "";
            StringBuilder builder = new StringBuilder();
            DataSet ds = new DataSet();
            
            string sql = "select top 5 PostTitle,PostID from Posts where typePost = 'TGG' ORDER BY DATEPOST";
            string url = ConfigurationManager.ConnectionStrings["ProjectDatabaseConnectionString2"].ToString();

            using (SqlConnection con = new SqlConnection(url))
            {
                using (SqlDataAdapter da = new SqlDataAdapter(sql,con))
                {
                    da.Fill(ds);
                }
            }

            foreach (DataRow item in ds.Tables[0].Rows)
            {
                builder.Append(@"<li><a href=""ReadNews.aspx?postid= " + item[1].ToString() +
                    @" ""> " + item[0].ToString().Trim() + "</a></li>\n");
            }

            st = builder.ToString();
            return st;
        }

        public string GetOtherNews()
        {
            string str = "";
            StringBuilder builder = new StringBuilder();
            DataSet ds = new DataSet();

            string sql = "select top 10 PostTitle,PostID from Posts ORDER BY NEWID()";
            string url = ConfigurationManager.ConnectionStrings["ProjectDatabaseConnectionString2"].ToString();

            using (SqlConnection con = new SqlConnection(url))
            {
                using (SqlDataAdapter da = new SqlDataAdapter(sql, con))
                {
                    da.Fill(ds);
                }
            }

            foreach (DataRow item in ds.Tables[0].Rows)
            {
                builder.Append(@"<li><a href=""ReadNews.aspx?postid= " + item[1].ToString() +
                    @" ""> " + item[0].ToString().Trim() + "</a></li>\n");
            }

            str = builder.ToString();

            return str;
        }
    }
}